﻿using jlynet.core.Library;
using jlynet.core.notebook.model;
using jlynet.core.notebook.util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace jlynet.core.notebook.myform
{
    public partial class AddDirectoryForm : Form
    {
        private DirectoryDataTableModel model;

        public AddDirectoryForm()
        {
            InitializeComponent();
        }

        public AddDirectoryForm(DirectoryDataTableModel model)
        {
            InitializeComponent();
            this.MinimizeBox = false;  //去掉最小化
            this.MaximizeBox = false;  //去掉最大化
            this.model = model;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (StringHelper.IsNullOrEmpty(this.textBox_directoryName.Text))
            {
                MessageBox.Show("请输入目录名称!", "提示");
                return;
            }
            Dictionary<string, object> dic_data = new Dictionary<string, object>();
            SQLiteConfigHelper.tableName = "directoryDataTable";
            DateTime dt = DateTime.Now;
            int time = TimeHelper.ConvertDateTimeInt(dt);
            if (StringHelper.IsNullOrEmpty(model.id))
            {
                model.id = "0";
            }
            dic_data["pid"] = model.id;
            dic_data["name_"] = this.textBox_directoryName.Text;
            dic_data["type_"] = model.type;
            dic_data["update_time"] = time;
            dic_data["create_time"] = time;
            long id = MySQLiteHelper.Insert(dic_data);
            if (id > 0)
            {
                MessageBox.Show("添加目录完成!", "提示");
                this.Dispose();
                this.Close();
                return;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Dispose();
            this.Close();
            return;
        }
    }
}
